package com.zito.health.controller;

import com.zito.health.common.annotations.ResponseResult;
import com.zito.health.common.result.PlatformResult;
import com.zito.health.common.result.VerifyResult;
import com.zito.health.entity.User;
import com.zito.health.service.MailService;
import com.zito.health.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.UUID;

@Slf4j
@ResponseResult
@RestController
@RequestMapping("/mail")
public class RetrievePasswordContorller {
    @Autowired
    MailService mailService ;

    /**
     * 获取重置密码的验证码
     *
     */
    @PostMapping("/sendMail")
    public PlatformResult sendMail(User user) throws MessagingException {
        PlatformResult result = new PlatformResult();
        String subject="密码找回";
        Integer res = mailService.send(subject, user);
        result.setStatus(res);
        if(res==200){
            result.setMsg("发送成功！");
        }else if(res==300){
            result.setMsg("登录名和邮箱不匹配！");
        }
        return result;
    }

    /**
     * 修改密码
     * @param user
     * @return
     * @throws MessagingException
     */
    @PostMapping("/modifyPwd")
    public PlatformResult modifyPwd(User user) {
        PlatformResult result = new PlatformResult();
        Integer res = mailService.modifyPwd(user);
        result.setStatus(res);
        if(res==200){
            result.setMsg("密码修改成功！");
        }else if(res == 300){
            result.setMsg("验证码已失效！");
        }
        return result;
    }





}
